using System;
using System.Web.UI;
using System.Web.Core;

namespace Forum.Business
{
    public class RoleEdit : ForumUserControl
    {
        protected ValuedTextBox subjectTextBox;
        protected ResourceButton saveButton;
        private int roleId = UrlManager.Instance.GetParameterValue<int>(ParameterName.RoleId);

        protected override void OnLoad(EventArgs e)
        {
            if (!Page.IsPostBack && !AjaxManager.IsCallBack)
            {
                BindData();
            }
            saveButton.Click += new EventHandler(SaveRole);
        }

        private void BindData()
        {
            Role role = RoleManager.GetRole(roleId);
            if (role != null)
            {
                subjectTextBox.Value = role.Name.Value;
            }
        }
        private void SaveRole(object sender, EventArgs e)
        {
            Role role = RoleManager.GetRole(roleId);
            if (role != null)
            {
                role.Name.Value = subjectTextBox.Value;
                RoleManager.Update(role);
            }

            Page.Response.Redirect(UrlManager.Instance.FormatUrl("role_list"));
        }
    }
}